<template>
  <Transition name="confirm-fade">
    <div class="custom-confirm-overlay" v-if="visible">
      <div class="custom-confirm-container">
        <div class="custom-confirm-header">
          <h3>{{ title }}</h3>
        </div>
        <div class="custom-confirm-content">
          <p>{{ message }}</p>
        </div>
        <div class="custom-confirm-footer">
          <button class="confirm-btn confirm" @click="$emit('confirm')">{{ confirmText }}</button>
          <button class="confirm-btn cancel" @click="$emit('cancel')">{{ cancelText }}</button>
        </div>
      </div>
    </div>
  </Transition>
</template>

<script setup>
defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  title: {
    type: String,
    default: '确认'
  },
  message: {
    type: String,
    default: '确定要执行此操作吗？'
  },
  confirmText: {
    type: String,
    default: '确定'
  },
  cancelText: {
    type: String,
    default: '取消'
  }
});

defineEmits(['confirm', 'cancel']);
</script>

<style scoped>
.custom-confirm-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.custom-confirm-container {
  width: 400px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.custom-confirm-header {
  padding: 15px 20px;
  background-color: #409EFF;
  color: #fff;
}

.custom-confirm-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.custom-confirm-content {
  padding: 20px;
  font-size: 16px;
  color: #606266;
  line-height: 1.5;
  text-align: center;
}

.custom-confirm-footer {
  padding: 10px 20px 20px;
  display: flex;
  justify-content: center;
  gap: 15px;
}

.confirm-btn {
  padding: 8px 20px;
  font-size: 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s;
  border: none;
  min-width: 50%;
  height: 40px;
}

.confirm-btn.confirm {
  background-color: #409EFF;
  color: #fff;
}

.confirm-btn.confirm:hover {
  background-color: #66b1ff;
}

.confirm-btn.cancel {
  background-color: #909399;
  color: #fff;
}

.confirm-btn.cancel:hover {
  background-color: #a6a9ad;
}

/* 过渡动画 */
.confirm-fade-enter-active,
.confirm-fade-leave-active {
  transition: opacity 0.3s, transform 0.3s;
}

.confirm-fade-enter-from,
.confirm-fade-leave-to {
  opacity: 0;
  transform: scale(0.8);
}
</style>